/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class Tbv_clienteDAOImpl implements orm.dao.Tbv_clienteDAO {
	public Tbv_cliente loadTbv_clienteByORMID(int cl_id_cliente) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_clienteByORMID(session, cl_id_cliente);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_cliente getTbv_clienteByORMID(int cl_id_cliente) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return getTbv_clienteByORMID(session, cl_id_cliente);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_cliente loadTbv_clienteByORMID(int cl_id_cliente, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_clienteByORMID(session, cl_id_cliente, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_cliente getTbv_clienteByORMID(int cl_id_cliente, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return getTbv_clienteByORMID(session, cl_id_cliente, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_cliente loadTbv_clienteByORMID(PersistentSession session, int cl_id_cliente) throws PersistentException {
		try {
			return (Tbv_cliente) session.load(orm.Tbv_cliente.class, new Integer(cl_id_cliente));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_cliente getTbv_clienteByORMID(PersistentSession session, int cl_id_cliente) throws PersistentException {
		try {
			return (Tbv_cliente) session.get(orm.Tbv_cliente.class, new Integer(cl_id_cliente));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_cliente loadTbv_clienteByORMID(PersistentSession session, int cl_id_cliente, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tbv_cliente) session.load(orm.Tbv_cliente.class, new Integer(cl_id_cliente), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_cliente getTbv_clienteByORMID(PersistentSession session, int cl_id_cliente, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tbv_cliente) session.get(orm.Tbv_cliente.class, new Integer(cl_id_cliente), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_cliente[] listTbv_clienteByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return listTbv_clienteByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_cliente[] listTbv_clienteByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return listTbv_clienteByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_cliente[] listTbv_clienteByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_cliente as Tbv_cliente");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Tbv_cliente[]) list.toArray(new Tbv_cliente[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_cliente[] listTbv_clienteByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_cliente as Tbv_cliente");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Tbv_cliente[]) list.toArray(new Tbv_cliente[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_cliente loadTbv_clienteByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_clienteByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_cliente loadTbv_clienteByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_clienteByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_cliente loadTbv_clienteByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Tbv_cliente[] tbv_clientes = listTbv_clienteByQuery(session, condition, orderBy);
		if (tbv_clientes != null && tbv_clientes.length > 0)
			return tbv_clientes[0];
		else
			return null;
	}
	
	public Tbv_cliente loadTbv_clienteByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Tbv_cliente[] tbv_clientes = listTbv_clienteByQuery(session, condition, orderBy, lockMode);
		if (tbv_clientes != null && tbv_clientes.length > 0)
			return tbv_clientes[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTbv_clienteByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return iterateTbv_clienteByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_clienteByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return iterateTbv_clienteByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_clienteByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_cliente as Tbv_cliente");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_clienteByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_cliente as Tbv_cliente");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_cliente createTbv_cliente() {
		return new orm.Tbv_cliente();
	}
	
	public boolean save(orm.Tbv_cliente tbv_cliente) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().saveObject(tbv_cliente);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Tbv_cliente tbv_cliente) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().deleteObject(tbv_cliente);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tbv_cliente tbv_cliente)throws PersistentException {
		try {
			orm.Tbv_maquina[] lTbv_maquinas = tbv_cliente.tbv_maquina.toArray();
			for(int i = 0; i < lTbv_maquinas.length; i++) {
				lTbv_maquinas[i].setTbv_clientecl_id_cliente(null);
			}
			return delete(tbv_cliente);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tbv_cliente tbv_cliente, org.orm.PersistentSession session)throws PersistentException {
		try {
			orm.Tbv_maquina[] lTbv_maquinas = tbv_cliente.tbv_maquina.toArray();
			for(int i = 0; i < lTbv_maquinas.length; i++) {
				lTbv_maquinas[i].setTbv_clientecl_id_cliente(null);
			}
			try {
				session.delete(tbv_cliente);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Tbv_cliente tbv_cliente) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().getSession().refresh(tbv_cliente);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Tbv_cliente tbv_cliente) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().getSession().evict(tbv_cliente);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_cliente loadTbv_clienteByCriteria(Tbv_clienteCriteria tbv_clienteCriteria) {
		Tbv_cliente[] tbv_clientes = listTbv_clienteByCriteria(tbv_clienteCriteria);
		if(tbv_clientes == null || tbv_clientes.length == 0) {
			return null;
		}
		return tbv_clientes[0];
	}
	
	public Tbv_cliente[] listTbv_clienteByCriteria(Tbv_clienteCriteria tbv_clienteCriteria) {
		return tbv_clienteCriteria.listTbv_cliente();
	}
}
